import 'package:flutter/material.dart';
import 'package:flutter_scan_tool/models/app_theme.dart';

import '../utils/mutable.dart';
import '../widget/custom_edit_field.dart';

// ignore: must_be_immutable
class EditFiledView extends StatefulWidget {
  final Mutable<String> content;
  ValueChanged<String> onValueChange;
  TextInputType? inputType;

  EditFiledView(
      {required Key key,
      required this.content,
      required this.onValueChange,
      this.inputType})
      : super(key: key);

  @override
  _EditFiledViewState createState() => _EditFiledViewState();
}

class _EditFiledViewState extends State<EditFiledView> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.black54,
      body: Center(
        child: Container(
          padding: const EdgeInsets.only(top: 32, bottom: 32),
          margin: const EdgeInsets.only(left: 32, right: 32),
          decoration: BoxDecoration(
              shape: BoxShape.rectangle,
              borderRadius: const BorderRadius.all(Radius.circular(15)),
              color: AppTheme.appTheme.cardBackgroundColor()),
          child: CustomEditField(
            inputType: widget.inputType,
            maxLength: 50,
            autoFucus: true,
            initValue: widget.content.value,
            hintText: '填入信息',
            hintTextStyle: AppTheme.appTheme
                .hint(fontWeight: FontWeight.normal, fontSize: 16),
            textStyle: AppTheme.appTheme
                .headline1(fontWeight: FontWeight.normal, fontSize: 16),
            minHeight: 100,
            containerDecoration: BoxDecoration(
                shape: BoxShape.rectangle,
                borderRadius: const BorderRadius.all(Radius.circular(15)),
                color: AppTheme.appTheme.containerBackgroundColor()),
            numDecoration: BoxDecoration(
                shape: BoxShape.rectangle,
                color: AppTheme.appTheme.cardBackgroundColor(),
                borderRadius: const BorderRadius.all(Radius.circular(15)),
                boxShadow: AppTheme.appTheme.containerBoxShadow()),
            numTextStyle: AppTheme.appTheme
                .themeText(fontWeight: FontWeight.bold, fontSize: 15),
            onValueChanged: (value) {
              widget.onValueChange(value);
            },
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          Navigator.of(context).pop();
        },
        child: const Icon(Icons.done),
        backgroundColor: AppTheme.appTheme.grandientColorStart(),
      ),
    );
  }
}
